cmake_minimum_required(VERSION 2.8)

project(ffdemo)

set(LFT_YUN_LIBS $ENV{LFT_YUN_LIBS})
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -g -O3 -fomit-frame-pointer -Wall -pthread")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wdeclaration-after-statement -Wdisabled-optimization -Wpointer-arith -Wredundant-decls -Wwrite-strings -Wtype-limits -Wundef -Wmissing-prototypes")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-pointer-to-int-cast -Wstrict-prototypes -Wempty-body -Wno-parentheses -Wno-switch -Wno-format-zero-length -Wno-pointer-sign -Wno-char-subscripts")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-math-errno -fno-signed-zeros -fno-tree-vectorize -Werror=format-security -Werror=implicit-function-declaration -Werror=missing-prototypes -Werror=return-type")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=vla -Wformat -fdiagnostics-color=auto -Wno-maybe-uninitialized")

if (CMAKE_SYSTEM_NAME MATCHES "Linux")
include_directories(
	${LFT_YUN_LIBS}/l-include/ffmpeg
	${LFT_YUN_LIBS}/l-include/ffmpeg/compat
)

link_directories(
	${LIBRARY_OUTPUT_PATH}
	${LFT_YUN_LIBS}/libs/linux
	${LFT_YUN_LIBS}/libs/linux/ffmpeg
)

set(PLATFORM_LIBS
	-lx264
	-lx265
	-lrtmp
	-llzma
	-lbz2
	-lm
	-lz
	-lxcb
	-lxcb-shm
	-lxcb-xfixes
	-lxcb-shape
	-lpthread
)

else ()
include_directories(
	${LFT_YUN_LIBS}/include/ffmpeg/gcc
	${LFT_YUN_LIBS}/include/ffmpeg
	${LFT_YUN_LIBS}/include/ffmpeg/compat
)

link_directories(
	${LIBRARY_OUTPUT_PATH}
	${LFT_YUN_LIBS}/libs/win-gcc
	${LFT_YUN_LIBS}/libs/win-gcc/ffmpeg
)

set(PLATFORM_LIBS
	-loleaut32
	-lole32
	-lshell32
	-lgdi32
	-lsecur32
	-lvfw32
	-lbcrypt
	-lzlib
)
endif ()

file(GLOB_RECURSE
	LIB_FILES
	"src/*.c"
)

add_library(fflib ${LIB_FILES})

##############################################################################
file(GLOB_RECURSE
	EXE_FILES
	"src/*.cpp"
)

add_executable(ffdemo ${EXE_FILES})
target_link_libraries(ffdemo
	-lfflib
	-lcmdutils
	-lavformat
	-lavdevice
	-lavfilter
	-lavcodec
	-lavutil
	-lswresample
	-lswscale
	${PLATFORM_LIBS}
	-lstdc++
)